import Vue from 'vue'
import Vuex from 'vuex'
import createLogger from 'vuex/dist/logger'
import state from './state'

Vue.use(Vuex)

//const debug = process.env.NODE_ENV !== 'production'

const store = new Vuex.Store({
	state,
	mutations:{
		setTid(state,payload){
			state.curTid = payload.curTid
		},
		setCurTid(state,payload){
			state.curTid=payload.curTid;
		}
	},
	getters:{
		getCurTid:(state)=>{
			let partitionList = window.__INITIAL_STATE__.reduxAsyncConnect.partitionList
			const hasCon = partitionList[state.curTid]
			if(!hasCon){
				const keyArr = Object.keys(partitionList)
//						核心代码:tid==obj.tid
						for(let i=0,len=keyArr.length;i<len;i++){
//							你一定要清楚,你访问的元素是什么
							const tmpArr = partitionList[keyArr[i]]
							for(let j=0,length=tmpArr.length;j<length;j++){
								if(tmpArr[j].tid==state.curTid){
									return state.curTid=keyArr[i]
								}
							}
						}
			}else{
					return state.curTid
				}
		}
	}, 	
//	plugins:debug ? [createLogger()] : []
})


export default store
